﻿using Song.Common.Tools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Dynamic;
using System.Xml.Linq;
using System.Linq;

namespace Test.Unit
{
    
    
    /// <summary>
    ///This is a test class for XmlMarkupBuilderTest and is intended
    ///to contain all XmlMarkupBuilderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class XmlMarkupBuilderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for XmlMarkupBuilder Constructor
        ///</summary>
        [TestMethod()]
        public void XmlMarkupBuilderConstructorTest()
        {
            dynamic target = new XmlMarkupBuilder();
            var persons = new[] {   new { name = "shen", age = 12, country = "China"},
                                    new { name = "li", age = 15, country = "English" },
                                    new { name = "wang", age = 14, country = "U.S" }};

            XElement resultXml = target.Persons(
                persons.Select(a => target.Person(Name: a.name, Age: a.age, Country: a.country))
                                );

            XElement resultXml2 = target.Persons(
                persons.Select(a => target.Person(target.Name(a.name, Age: a.age), target.Country(a.country)))
                    );

            XElement Comperxml1 = new XElement("Persons");
            foreach (var p in persons)
            {
                XElement pl = new XElement("Person", 
                                            new XAttribute("Name", p.name), 
                                            new XAttribute("Age", p.age), 
                                            new XAttribute("Country",p.country)
                                            );
                Comperxml1.Add(pl);
            }


            XElement Comperxml2 = new XElement("Persons");
            foreach (var p in persons)
            {
                XElement pl = new XElement("Person",
                                            new XElement("Name", new XAttribute("Age", p.age),p.name),
                                            new XElement("Country", p.country)
                                            );
                Comperxml2.Add(pl);
            }
            Assert.AreEqual(resultXml.ToString(), Comperxml1.ToString());
            Assert.AreEqual(resultXml2.ToString(), Comperxml2.ToString());
        }

        /// <summary>
        ///A test for TryInvokeMember
        ///</summary>
        [TestMethod()]
        public void TryInvokeMemberTest()
        {
            XmlMarkupBuilder target = new XmlMarkupBuilder(); // TODO: Initialize to an appropriate value
            InvokeMemberBinder binder = null; // TODO: Initialize to an appropriate value
            object[] args = null; // TODO: Initialize to an appropriate value
            object result = null; // TODO: Initialize to an appropriate value
            object resultExpected = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.TryInvokeMember(binder, args, out result);
            Assert.AreEqual(resultExpected, result);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
